import { defineStore } from "pinia";
import * as lodash from "lodash-es";

export interface IAnimationConfig {
  speed: number; // 动画播放的倍速
  time: number; // 动画的持续时间，时间到后动画停止 单位：s
  scale: number;
  xMax: number;
  yMax: number;
}

export interface IObjectConfig {
  x: number; // 起始 x 坐标
  y: number; // 起始 y 坐标
  speed: number; // 运动的速度
  direction: number; // 物体初始的方向， 所有物体都是直线运行 单位: 度

  scale: number;
  colors?: string[]; // 物体的颜色数组
}

interface store {
  // 程序的全局配置
  global: IAnimationConfig;

  // 两个物体的配置
  first: IObjectConfig;
  second: IObjectConfig;
}

export const useConfigStore = defineStore({
  id: "config",
  state: (): store => ({
    global: {
      speed: 0.25,
      time: 10,
      scale: 1,
      xMax: 1022,
      yMax: 1022,
    },
    first: {
      x: 30,
      y: 30,
      speed: 5,
      direction: -90,
      colors: ["red"],
      scale: 1,
    },
    second: {
      x: 3002,
      y: 1002,
      speed: 5,
      direction: 135,
      colors: ["blue"],
      scale: 1,
    },
  }),
  getters: {
    xMax(): number {
      return <number>lodash.max([this.first.x + 20, this.second.x + 20]);
    },
    yMax(): number {
      return <number>lodash.max([this.first.y + 20, this.second.y + 20]);
    },
  },
});
